<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="renderer" content="webkit"><meta name="format-detection" content="telephone=no"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><link rel="icon" href="/images/icons/favicon-16x16.png?v=2.0.0-rc.0" type="image/png" sizes="16x16"><link rel="icon" href="/images/icons/favicon-32x32.png?v=2.0.0-rc.0" type="image/png" sizes="32x32"><meta name="description" content="1.什么是微服务架构       　　微服务架构是一种架构模式或者架构风格，它提倡将单一应用程序分成一组小的服务，每个服务运行在其独立的自己的进程中，服务之间互相协调，配合，为用户提供最终价值。">
<meta property="og:type" content="article">
<meta property="og:title" content="SpringCloud 学习">
<meta property="og:url" content="http://yoursite.com/2020/09/07/SpringCloud-%E5%AD%A6%E4%B9%A0/index.html">
<meta property="og:site_name" content="孙宇的博客">
<meta property="og:description" content="1.什么是微服务架构       　　微服务架构是一种架构模式或者架构风格，它提倡将单一应用程序分成一组小的服务，每个服务运行在其独立的自己的进程中，服务之间互相协调，配合，为用户提供最终价值。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://yoursite.com/2020/09/07/SpringCloud-%E5%AD%A6%E4%B9%A0/springcloud_1.png">
<meta property="article:published_time" content="2020-09-07T15:55:53.000Z">
<meta property="article:modified_time" content="2021-08-06T11:52:34.204Z">
<meta property="article:author" content="孙宇">
<meta property="article:tag" content="Spring Cloud 学习">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yoursite.com/2020/09/07/SpringCloud-%E5%AD%A6%E4%B9%A0/springcloud_1.png"><meta name="keywords" content="孙宇, 孙宇的博客"><meta name="description" content=""><title>SpringCloud 学习 | 孙宇的博客</title><link ref="canonical" href="http://yoursite.com/2020/09/07/SpringCloud-%E5%AD%A6%E4%B9%A0/"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.12.1/css/all.min.css" type="text/css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@latest/dist/gitalk.min.css" type="text/css"><link rel="stylesheet" href="/css/index.css?v=2.0.0-rc.0"><script>var Stun = window.Stun || {};
var CONFIG = {
  root: '/',
  algolia: undefined,
  fontIcon: {"prompt":{"success":"fas fa-check-circle","info":"fas fa-arrow-circle-right","warning":"fas fa-exclamation-circle","error":"fas fa-times-circle"},"copyBtn":"fas fa-copy"},
  sidebar: {"offsetTop":"20px","tocMaxDepth":6},
  header: {"enable":true,"showOnPost":true,"scrollDownIcon":true},
  postWidget: {"endText":true},
  nightMode: {"enable":true},
  back2top: {"enable":true},
  codeblock: {"style":"default","highlight":"light","wordWrap":false},
  reward: false,
  fancybox: false,
  zoomImage: {"gapAside":"20px"},
  galleryWaterfall: undefined,
  lazyload: false,
  pjax: undefined,
  externalLink: {"icon":{"enable":true,"name":"fas fa-external-link-alt"}},
  shortcuts: {"switchPost":true},
  prompt: {"copyButton":"复制","copySuccess":"复制成功","copyError":"复制失败"},
  sourcePath: {"js":"js","css":"css","images":"images"},
};

window.CONFIG = CONFIG;</script><meta name="generator" content="Hexo 5.0.2"></head><body><div class="container" id="container"><header class="header" id="header"><div class="header-inner"><nav class="header-nav header-nav--fixed"><div class="header-nav-inner"><div class="header-nav-menubtn"><i class="fas fa-bars"></i></div><div class="header-nav-menu"><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/"><span class="header-nav-menu-item__icon"><i class="fas fa-home"></i></span><span class="header-nav-menu-item__text">首页</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/archives/"><span class="header-nav-menu-item__icon"><i class="fas fa-folder-open"></i></span><span class="header-nav-menu-item__text">归档</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/categories/"><span class="header-nav-menu-item__icon"><i class="fas fa-layer-group"></i></span><span class="header-nav-menu-item__text">分类</span></a></div><div class="header-nav-menu-item"><a class="header-nav-menu-item__link" href="/tags/"><span class="header-nav-menu-item__icon"><i class="fas fa-tags"></i></span><span class="header-nav-menu-item__text">标签</span></a></div></div><div class="header-nav-search"><span class="header-nav-search__icon"><i class="fas fa-search"></i></span><span class="header-nav-search__text">搜索</span></div><div class="header-nav-mode"><div class="mode"><div class="mode-track"><span class="mode-track-moon"></span><span class="mode-track-sun"></span></div><div class="mode-thumb"></div></div></div></div></nav><div class="header-banner"><div class="header-banner-info"><div class="header-banner-info__title">孙宇的博客</div><div class="header-banner-info__subtitle">博客小白，正在学习中。如果有更好的意见欢迎反馈。</div></div><div class="header-banner-arrow"><div class="header-banner-arrow__icon"><i class="fas fa-angle-down"></i></div></div></div></div></header><main class="main" id="main"><div class="main-inner"><div class="content-wrap" id="content-wrap"><div class="content" id="content"><!-- Just used to judge whether it is an article page--><div id="is-post"></div><div class="post"><header class="post-header"><h1 class="post-title">SpringCloud 学习</h1><div class="post-meta"><span class="post-meta-item post-meta-item--createtime"><span class="post-meta-item__icon"><i class="far fa-calendar-plus"></i></span><span class="post-meta-item__info">发表于</span><span class="post-meta-item__value">2020-09-07</span></span><span class="post-meta-item post-meta-item--updatetime"><span class="post-meta-item__icon"><i class="far fa-calendar-check"></i></span><span class="post-meta-item__info">更新于</span><span class="post-meta-item__value">2021-08-06</span></span><span class="post-meta-item post-meta-item--wordcount"><span class="post-meta-item__icon"><i class="far fa-file-word"></i></span><span class="post-meta-item__info">字数统计</span><span class="post-meta-item__value">1.6k</span></span></div></header><div class="post-body">
        <h1 id="1-什么是微服务架构">
          <a href="#1-什么是微服务架构" class="heading-link"><i class="fas fa-link"></i></a>1.什么是微服务架构</h1>
      <p>　　微服务架构是一种架构模式或者架构风格，<font color="red">它提倡将单一应用程序分成一组小的服务</font>，每个服务运行在其独立的自己的进程中，服务之间互相协调，配合，为用户提供最终价值。</p>
<a id="more"></a>


        <h1 id="2-什么是SpringCloud">
          <a href="#2-什么是SpringCloud" class="heading-link"><i class="fas fa-link"></i></a>2.什么是SpringCloud</h1>
      <p>　　<strong>SpringCloud</strong> 就是分布式微服务架构下的一站式解决方案，是各个微服务架构落地技术的集合体，俗称为服务全家桶</p>

        <h1 id="3-SpringCloud-和-SpringBoot-是什么关系">
          <a href="#3-SpringCloud-和-SpringBoot-是什么关系" class="heading-link"><i class="fas fa-link"></i></a>3.SpringCloud 和 SpringBoot 是什么关系</h1>
      <ol>
<li><p><strong>SpringBoot：</strong>专注于快速方便的开发单个个体微服务</p>
<p><strong>SpringCloud：</strong>是关注全局的微服务协调整理治理框架，它将 <strong>SpringBoot</strong> 开发的一个个单体微服务整合并管理起来，为各个微服务之间提供，管理配置、服务发现、断路器、路由、微代理、事件总线、全局锁、决策竞选、分布式会话等等集成服务</p>
</li>
<li><p><strong>SpringBoot</strong> 可以离开 <strong>SpringCloud</strong> 独立使用开发项目，但是 <strong>SpringCloud</strong> 离不开 <strong>SpringBoot</strong>，属于依赖关系。</p>
</li>
</ol>
<p>总的来说，<strong>SpringBoot</strong> 专注于快速、方便的开发单个微服务个体，<strong>SpringCloud</strong> 关注全局的服务治理框架</p>

        <h1 id="4-SpringCloud-和-Dubbo-有什么区别？">
          <a href="#4-SpringCloud-和-Dubbo-有什么区别？" class="heading-link"><i class="fas fa-link"></i></a>4.SpringCloud 和 Dubbo 有什么区别？</h1>
      <ol>
<li><p>在通讯机制方面：</p>
<p><strong>Dubbo</strong> 是通过 <strong>RPC</strong> 远程过程调用</p>
<p><strong>SpringCloud</strong> 是通过基于 <strong>HTTP</strong> 的 <strong>RESTful api</strong></p>
</li>
<li><p>在自身技术方面：</p>
<p><strong>Dubbo</strong> 就是像组装机，使用的基本都是第三方。选择的自由度很高，但是出问题的可能性也会随之提高。</p>
<p><strong>SpringCloud</strong> 就像是买的一体机，一整套都是自己的。在 <strong>Spring Source</strong> 的整合下，做了大量的稳定性测试，使其拥有更高的稳定性。</p>
<p>具体见表：</p>
<div class="table-container"><table>
<thead>
<tr>
<th align="left"></th>
<th align="left">Dubbo</th>
<th align="left">Spring Cloud</th>
</tr>
</thead>
<tbody><tr>
<td align="left">服务注册中心</td>
<td align="left">Zookeeper</td>
<td align="left">Spring Cloud Netflix Eureka</td>
</tr>
<tr>
<td align="left">服务调用方式</td>
<td align="left">RPC</td>
<td align="left">REST API</td>
</tr>
<tr>
<td align="left">服务监控</td>
<td align="left">Duboo-monitor</td>
<td align="left">Spring Boot Admin</td>
</tr>
<tr>
<td align="left">断路器</td>
<td align="left">不完善</td>
<td align="left">Spring Cloud Netflix Hystrix</td>
</tr>
<tr>
<td align="left">服务网关</td>
<td align="left">无</td>
<td align="left">Spring Cloud Netflix Zuul</td>
</tr>
<tr>
<td align="left">分布式配置</td>
<td align="left">无</td>
<td align="left">Spring Cloud Config</td>
</tr>
<tr>
<td align="left">服务跟踪</td>
<td align="left">无</td>
<td align="left">Spring Cloud Sleuth</td>
</tr>
<tr>
<td align="left">消息总线</td>
<td align="left">无</td>
<td align="left">Spring Cloud Bus</td>
</tr>
<tr>
<td align="left">数据流</td>
<td align="left">无</td>
<td align="left">Spring Cloud Stream</td>
</tr>
<tr>
<td align="left">批量任务</td>
<td align="left">无</td>
<td align="left">Spring Cloud Task</td>
</tr>
<tr>
<td align="left">……</td>
<td align="left">……</td>
<td align="left">……</td>
</tr>
</tbody></table></div>
</li>
</ol>
<p><strong>开发参考文档地址：</strong></p>
<p>　　中文版API：<span class="exturl"><a class="exturl__link" target="_blank" rel="noopener" href="https://www.springcloud.cc/spring-cloud-dalston.html">https://www.springcloud.cc/spring-cloud-dalston.html</a><span class="exturl__icon"><i class="fas fa-external-link-alt"></i></span></span></p>
<p>　　springcloud中国社区：<span class="exturl"><a class="exturl__link" target="_blank" rel="noopener" href="http://springcloud.cn/">http://springcloud.cn/</a><span class="exturl__icon"><i class="fas fa-external-link-alt"></i></span></span></p>
<p>　　springcloud中文网：<span class="exturl"><a class="exturl__link" target="_blank" rel="noopener" href="https://www.springcloud.cc/">https://www.springcloud.cc/</a><span class="exturl__icon"><i class="fas fa-external-link-alt"></i></span></span></p>
<p>至此，理论概念部分完成，接下来就是代码案例的编写了。</p>

        <h1 id="5-代码案例">
          <a href="#5-代码案例" class="heading-link"><i class="fas fa-link"></i></a>5.代码案例</h1>
      
        <h2 id="1-Rest微服务案例-父工程构建">
          <a href="#1-Rest微服务案例-父工程构建" class="heading-link"><i class="fas fa-link"></i></a>1)Rest微服务案例-父工程构建</h2>
      <p>首先，在working set 中新建一个maven porject。</p>
<p>Artifact Id：父工程的名字</p>
<p>Packaging：pom</p>
<p><img src="/2020/09/07/SpringCloud-%E5%AD%A6%E4%B9%A0/springcloud_1.png" alt="图片加载失败"></p>

        <h2 id="2-pom文件编写">
          <a href="#2-pom文件编写" class="heading-link"><i class="fas fa-link"></i></a>2)pom文件编写</h2>
      <figure class="highlight xml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"></span><br></pre></td></tr></table></div></figure>




        <h1 id="框架搭建过程中发生的问题与解决方式">
          <a href="#框架搭建过程中发生的问题与解决方式" class="heading-link"><i class="fas fa-link"></i></a>*框架搭建过程中发生的问题与解决方式</h1>
      
        <h2 id="1-启动报错">
          <a href="#1-启动报错" class="heading-link"><i class="fas fa-link"></i></a>1) 启动报错</h2>
      <ol>
<li><p><font color="red"><strong>java.lang.ClassNotFoundException: org.springframework.boot.bind.RelaxedPropertyResolver </strong></font></p>
<p> 　　关于这个报错信息我也百度了好久，说什么的都有，基本说的都是依赖版本问题，我也是一顿调整问题，后来将光标移动到了启动类的 <strong>@SpringBootApplication</strong> 注解上发现 <strong>spring-boot-autoconfigure</strong> 的版本为 1.5.X。因为我的父级 <strong>pom</strong> 中定义了 <strong>springboot starter</strong> 的版本为 <strong>2.4.5</strong> 所以意识到不对了。后来手动引入 <strong>spring-boot-autoconfigure</strong> 解决这个问题</p>
<figure class="highlight xml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-autoconfigure<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;springboot.stater.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></div></figure>


</li>
</ol>

        <h2 id="2）扫描不到mapper接口">
          <a href="#2）扫描不到mapper接口" class="heading-link"><i class="fas fa-link"></i></a>2）扫描不到mapper接口</h2>
      <ol>
<li><p><font color="red"><strong>org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)</strong></font></p>
<p>这个报错产生的原因很多，列出我知道的几种</p>
<ul>
<li>mybatisPlusConfig 配置文件类上是否加入了 @MapperScan(”mapper路径“) 注解</li>
<li>yml.xml 配置文件中 的 mapper.xml 文件扫描路径配置是否正确</li>
<li>mapper.xml 文件存放路径是否正确，spring boot 默认是不会将 java 文件夹下的非java文件打包。所以如果mapper.xml文件应该放在 resource 静态资源路径下，如果放在 java文件夹下，则需要在 pom 中配置 resources 将xml打包</li>
<li>idea 开发工具项目文件路径问题，idea是会隐藏空文件夹的，例如有的时候我们在resource 下创建了 mybatis.mapper 用来存放 mapper.xml 文件。这个时候的 mybatis.mapper 文件夹在 idea 中你可能认为他是两个文件夹，但是如果你在系统中找到这个文件夹，这个文件夹可能并不是在 mybatis 文件中还有一个 mapper 文件夹，而是有一个叫 mybatis.mapper 的文件夹。这个真的要注意。</li>
</ul>
<p><font color="red"><strong>*</strong></font><strong>我这里就是犯了最后一个错误，我怎么也没想到 idea 的这个问题，他创建多级空目录会有这个问题，我知道，但是就没有往这边想，为此我付出了 <font color="red" size="5">5</font> 个小时的代价。特此记录，引以为戒</strong></p>
</li>
</ol>

        <h2 id="3）swagger-3-0版本注意事项">
          <a href="#3）swagger-3-0版本注意事项" class="heading-link"><i class="fas fa-link"></i></a>3）swagger 3.0版本注意事项</h2>
      <ol>
<li><p>本来小编用的是 <strong>swagger2</strong> 的版本，结果因为搭建项目框架，有的依赖有问题，切换了 <strong>swagger</strong> 的版本为：3.0.0.。切换之后服务可以正常启动，但是访问不了 <strong>swagger</strong> 的页面了。*(访问地址：swagger-ui.html)* </p>
<p><strong>解决：</strong></p>
<ol>
<li><p>swagger3.0 需要在 pom 中添加以下依赖：</p>
<figure class="highlight xml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.springfox<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>springfox-boot-starter<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>3.0.0<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></div></figure>
</li>
<li><p>需要在启动类增加 <strong>@EnableOpenApi</strong> 注解</p>
</li>
<li><p>访问地址变为：xxx/swagger-ui/index.html</p>
</li>
</ol>
</li>
</ol>

        <h2 id="4）Erueka-报错">
          <a href="#4）Erueka-报错" class="heading-link"><i class="fas fa-link"></i></a>4）Erueka 报错</h2>
      <ol>
<li><p><font color="red">启动报错：spring cloud erueka  com.google.gson.GsonBuilder:</font></p>
<p>升级 gson 的版本即可</p>
</li>
<li><p>访问eureka 中服务的info–》/actuator/info 404 问题</p>
<ul>
<li><p>修改父工程pom</p>
<figure class="highlight xml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">build</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">finalName</span>&gt;</span>springCloud<span class="tag">&lt;/<span class="name">finalName</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">resources</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">resource</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">directory</span>&gt;</span>src/main/resources<span class="tag">&lt;/<span class="name">directory</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">filtering</span>&gt;</span>true<span class="tag">&lt;/<span class="name">filtering</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">resource</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">resources</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">plugins</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">plugin</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.apache.maven.plugins<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>maven-resources-plugin<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">version</span>&gt;</span>$&#123;maven.resources.version&#125;<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">configuration</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;<span class="name">delimiters</span>&gt;</span></span><br><span class="line">                    <span class="comment">&lt;!--这里使用与匹配yml中的配置，需要注意有的版本这里用的是&lt;delimit&gt;标签--&gt;</span></span><br><span class="line">                    <span class="tag">&lt;<span class="name">delimiter</span>&gt;</span>$<span class="tag">&lt;/<span class="name">delimiter</span>&gt;</span></span><br><span class="line">                <span class="tag">&lt;/<span class="name">delimiters</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;/<span class="name">configuration</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">plugin</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">plugins</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">build</span>&gt;</span></span><br></pre></td></tr></table></div></figure>
</li>
<li><p>修改子工程yml配置文件</p>
<figure class="highlight yaml"><div class="table-container"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">eureka:</span></span><br><span class="line">  <span class="comment"># 客户端注册进eureka服务列表内</span></span><br><span class="line">  <span class="attr">client:</span></span><br><span class="line">    <span class="attr">service-url:</span></span><br><span class="line">      <span class="comment"># 对应eureka服务端的defaultZone</span></span><br><span class="line">      <span class="attr">defaultZone:</span> <span class="string">http://localhost:7001/eureka</span></span><br><span class="line">  <span class="comment"># 实例配置</span></span><br><span class="line">  <span class="attr">instance:</span></span><br><span class="line">    <span class="comment"># 实例id，eureka 中实例名称，status显示的名称</span></span><br><span class="line">    <span class="attr">instance-id:</span> <span class="string">ProViderDept8001</span></span><br><span class="line">    <span class="comment"># 配置访问路径可以显示ip地址</span></span><br><span class="line">    <span class="attr">prefer-ip-address:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">info:</span></span><br><span class="line">  <span class="attr">app.name:</span> <span class="string">springCloud</span></span><br><span class="line">  <span class="attr">company.name:</span> <span class="string">www.sy.com</span></span><br><span class="line">  <span class="attr">build.artifactId:</span> <span class="string">$project.artifactId$</span></span><br><span class="line">  <span class="attr">build.version:</span> <span class="string">$project.version$</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#此处配置用于开发eureka 的actuator/info 信息使用</span></span><br><span class="line"><span class="attr">management:</span></span><br><span class="line">  <span class="attr">endpoints:</span></span><br><span class="line">    <span class="attr">web:</span></span><br><span class="line">      <span class="attr">exposure:</span></span><br><span class="line"><span class="comment">#       开放所有</span></span><br><span class="line">        <span class="attr">include:</span> <span class="string">&quot;*&quot;</span></span><br></pre></td></tr></table></div></figure>

</li>
</ul>
</li>
</ol>
</div><footer class="post-footer"><div class="post-ending ending"><div class="ending__text">------ 本文结束，感谢您的阅读 ------</div></div><div class="post-copyright copyright"><div class="copyright-author"><span class="copyright-author__name">本文作者: </span><span class="copyright-author__value"><a href="http://yoursite.com">孙宇</a></span></div><div class="copyright-link"><span class="copyright-link__name">本文链接: </span><span class="copyright-link__value"><a href="http://yoursite.com/2020/09/07/SpringCloud-%E5%AD%A6%E4%B9%A0/">http://yoursite.com/2020/09/07/SpringCloud-%E5%AD%A6%E4%B9%A0/</a></span></div><div class="copyright-notice"><span class="copyright-notice__name">版权声明: </span><span class="copyright-notice__value">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" rel="external nofollow" target="_blank">BY-NC-SA</a> 许可协议。转载请注明出处！</span></div></div><div class="post-tags"><span class="post-tags-item"><span class="post-tags-item__icon"><i class="fas fa-tag"></i></span><a class="post-tags-item__link" href="http://yoursite.com/tags/Spring-Cloud-%E5%AD%A6%E4%B9%A0/">Spring Cloud 学习</a></span></div><nav class="post-paginator paginator"><div class="paginator-prev"><a class="paginator-prev__link" href="/2021/08/06/Redis%E5%AD%A6%E4%B9%A0/"><span class="paginator-prev__icon"><i class="fas fa-angle-left"></i></span><span class="paginator-prev__text">Redis学习</span></a></div><div class="paginator-next"><a class="paginator-next__link" href="/2020/08/04/Ubuntu%E7%A0%B4%E8%A7%A3Jetbrains%E5%B7%A5%E5%85%B7/"><span class="paginator-prev__text">Ubuntu破解Jetbrains工具</span><span class="paginator-next__icon"><i class="fas fa-angle-right"></i></span></a></div></nav></footer></div></div><div class="comments" id="comments"><div id="gitalk-container"></div></div></div><div class="sidebar-wrap" id="sidebar-wrap"><aside class="sidebar" id="sidebar"><div class="sidebar-nav"><span class="sidebar-nav-toc current">文章目录</span><span class="sidebar-nav-ov">站点概览</span></div><section class="sidebar-toc"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#1-%E4%BB%80%E4%B9%88%E6%98%AF%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%9E%B6%E6%9E%84"><span class="toc-text">
          1.什么是微服务架构</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#2-%E4%BB%80%E4%B9%88%E6%98%AFSpringCloud"><span class="toc-text">
          2.什么是SpringCloud</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#3-SpringCloud-%E5%92%8C-SpringBoot-%E6%98%AF%E4%BB%80%E4%B9%88%E5%85%B3%E7%B3%BB"><span class="toc-text">
          3.SpringCloud 和 SpringBoot 是什么关系</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#4-SpringCloud-%E5%92%8C-Dubbo-%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB%EF%BC%9F"><span class="toc-text">
          4.SpringCloud 和 Dubbo 有什么区别？</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#5-%E4%BB%A3%E7%A0%81%E6%A1%88%E4%BE%8B"><span class="toc-text">
          5.代码案例</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-Rest%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%A1%88%E4%BE%8B-%E7%88%B6%E5%B7%A5%E7%A8%8B%E6%9E%84%E5%BB%BA"><span class="toc-text">
          1)Rest微服务案例-父工程构建</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-pom%E6%96%87%E4%BB%B6%E7%BC%96%E5%86%99"><span class="toc-text">
          2)pom文件编写</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%A1%86%E6%9E%B6%E6%90%AD%E5%BB%BA%E8%BF%87%E7%A8%8B%E4%B8%AD%E5%8F%91%E7%94%9F%E7%9A%84%E9%97%AE%E9%A2%98%E4%B8%8E%E8%A7%A3%E5%86%B3%E6%96%B9%E5%BC%8F"><span class="toc-text">
          *框架搭建过程中发生的问题与解决方式</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-%E5%90%AF%E5%8A%A8%E6%8A%A5%E9%94%99"><span class="toc-text">
          1) 启动报错</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2%EF%BC%89%E6%89%AB%E6%8F%8F%E4%B8%8D%E5%88%B0mapper%E6%8E%A5%E5%8F%A3"><span class="toc-text">
          2）扫描不到mapper接口</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3%EF%BC%89swagger-3-0%E7%89%88%E6%9C%AC%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9"><span class="toc-text">
          3）swagger 3.0版本注意事项</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4%EF%BC%89Erueka-%E6%8A%A5%E9%94%99"><span class="toc-text">
          4）Erueka 报错</span></a></li></ol></li></ol></section><!-- ov = overview--><section class="sidebar-ov hide"><div class="sidebar-ov-author"><div class="sidebar-ov-author__avatar"><img class="sidebar-ov-author__avatar_img" src="/images/img_head.jpg" alt="avatar"></div><p class="sidebar-ov-author__text">悠闲时光</p></div><div class="sidebar-ov-state"><a class="sidebar-ov-state-item sidebar-ov-state-item--posts" href="/archives/"><div class="sidebar-ov-state-item__count">14</div><div class="sidebar-ov-state-item__name">归档</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--categories" href="/categories/"><div class="sidebar-ov-state-item__count">10</div><div class="sidebar-ov-state-item__name">分类</div></a><a class="sidebar-ov-state-item sidebar-ov-state-item--tags" href="/tags/"><div class="sidebar-ov-state-item__count">7</div><div class="sidebar-ov-state-item__name">标签</div></a></div><div class="sidebar-ov-cc"><a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en" target="_blank" rel="noopener" data-popover="知识共享许可协议" data-popover-pos="up"><img src="/images/cc-by-nc-sa.svg"></a></div></section><div class="sidebar-reading"><div class="sidebar-reading-info"><span class="sidebar-reading-info__text">你已阅读了 </span><span class="sidebar-reading-info__num">0</span></div><div class="sidebar-reading-line"></div></div></aside></div><div class="clearfix"></div></div></main><footer class="footer" id="footer"><div class="footer-inner"><div><span>Copyright © 2021</span><span class="footer__icon"><i class="fas fa-heart"></i></span><span>孙宇</span></div><div><span>由 <a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a> 强力驱动</span><span> v5.0.2</span><span class="footer__devider">|</span><span>主题 - <a href="https://github.com/liuyib/hexo-theme-stun/" title="Stun" target="_blank" rel="noopener">Stun</a></span><span> v2.0.0-rc.0</span></div></div></footer><div class="loading-bar" id="loading-bar"><div class="loading-bar__progress"></div></div><div class="back2top" id="back2top"><span class="back2top__icon"><i class="fas fa-rocket"></i></span></div></div><div class="search-mask"></div><div class="search-popup"><span class="search-close"></span><div class="search-input"><input placeholder="搜索文章（支持多关键词，请用空格分隔）"></div><div class="search-results"></div></div><script src="https://cdn.jsdelivr.net/npm/jquery@v3.4.1/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@1.5.2/velocity.ui.min.js"></script><script src="https://cdn.jsdelivr.net/npm/ribbon.js@latest/dist/ribbon.min.js" size="120" alpha="0.6" zIndex="-1"></script><script src="https://cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-nest@latest/canvas-nest.min.js" color="1,0,0" opacity="0.6" count="99" zIndex="-1"></script><script>function initSearch() {
  var isXML = true;
  var search_path = 'search.json';

  if (!search_path) {
    search_path = 'search.xml';
  } else if (/json$/i.test(search_path)) {
    isXML = false;
  }

  var path = '/' + search_path;
  $.ajax({
    url: path,
    dataType: isXML ? 'xml' : 'json',
    async: true,
    success: function (res) {
      var datas = isXML ? $('entry', res).map(function () {
        // 将 XML 转为 JSON
        return {
          title: $('title', this).text(),
          content: $('content', this).text(),
          url: $('url', this).text()
        };
      }).get() : res;
      var $input = $('.search-input input');
      var $result = $('.search-results');
      // 搜索对象（标题、内容）的权重，影响显示顺序
      var WEIGHT = { title: 100, content: 1 };
      var searchPost = function () {
        var searchText = $input.val().toLowerCase().trim();
        // 根据空白字符分隔关键字
        var keywords = searchText.split(/[\s]+/);
        // 搜索结果
        var matchPosts = [];

        // 有多个关键字时，将原文字整个保存下来
        if (keywords.length > 1) {
          keywords.push(searchText);
        }
        // 防止未输入字符时搜索
        if (searchText.length > 0) {
          datas.forEach(function (data) {
            var isMatch  = false;
            // 没有标题的文章使用预设的 i18n 变量代替
            var title = (data.title && data.title.trim()) || '[ 文章无标题 ]';
            var titleLower = title && title.toLowerCase();
            // 删除 HTML 标签 和 所有空白字符
            var content = data.content && data.content.replace(/<[^>]+>/g, '');
            var contentLower = content && content.toLowerCase();
            // 删除重复的 /
            var postURL = data.url && decodeURI(data.url).replace(/\/{2,}/g, '/');
            // 标题中匹配到的关键词
            var titleHitSlice = [];
            // 内容中匹配到的关键词
            var contentHitSlice = [];

            keywords.forEach(function (keyword) {
              /**
              * 获取匹配的关键词的索引
              * @param {String} keyword 要匹配的关键字
              * @param {String} text 原文字
              * @param {Boolean} caseSensitive 是否区分大小写
              * @param {Number} weight 匹配对象的权重。权重大的优先显示
              * @return {Array}
              */
              function getIndexByword (word, text, caseSensitive, weight) {
                if (!word || !text) {
                  return [];
                };

                var startIndex = 0; // 每次匹配的开始索引
                var index = -1;     // 匹配到的索引值
                var result = [];    // 匹配结果

                if (!caseSensitive) {
                  word = word.toLowerCase();
                  text = text.toLowerCase();
                }

                while((index = text.indexOf(word, startIndex)) !== -1) {
                  var hasMatch = false;
                  // 索引位置相同的关键词，保留长度较长的
                  titleHitSlice.forEach(function (hit) {
                    if (hit.index === index && hit.word.length < word.length) {
                      hit.word = word;
                      hasMatch = true;
                    }
                  });
                  startIndex = index + word.length;
                  !hasMatch && result.push({ index: index, word: word, weight: weight });
                }
                return result;
              }
              titleHitSlice = titleHitSlice.concat(getIndexByword(keyword, titleLower, false, WEIGHT.title));
              contentHitSlice = contentHitSlice.concat(getIndexByword(keyword, contentLower, false, WEIGHT.content));
            });

            var hitTitle = titleHitSlice.length;
            var hitContent = contentHitSlice.length;

            if (hitTitle > 0 || hitContent > 0) {
              isMatch = true;
            }
            if (isMatch) {
              ;[titleHitSlice, contentHitSlice].forEach(function (hit) {
                // 按照匹配文字的索引的递增顺序排序
                hit.sort(function (left, right) {
                  return left.index - right.index;
                });
              });
              /**
              * 给文本中匹配到的关键词添加标记，从而进行高亮显示
              * @param {String} text 原文本
              * @param {Array} hitSlice 匹配项的索引信息
              * @param {Number} start 开始索引
              * @param {Number} end 结束索引
              * @return {String}
              */
              function highlightKeyword (text, hitSlice, start, end) {
                if (!text || !hitSlice || !hitSlice.length) {
                  return;
                }

                var result = '';
                var startIndex = start;
                var endIndex = end;
                hitSlice.forEach(function (hit) {
                  if (hit.index < startIndex) {
                    return;
                  }

                  var hitWordEnd = hit.index + hit.word.length;
                  result += text.slice(startIndex, hit.index);
                  result += '<b>' + text.slice(hit.index, hitWordEnd) + '</b>';
                  startIndex = hitWordEnd;
                });
                result += text.slice(startIndex, endIndex);
                return result;
              }

              var postData = {};
              // 文章总的搜索权重
              var postWeight = titleHitSlice.length * WEIGHT.title + contentHitSlice.length * WEIGHT.content;
              // 标记匹配关键词后的标题
              var postTitle = highlightKeyword(title, titleHitSlice, 0, title.length) || title;
              // 标记匹配关键词后的内容
              var postContent;
              // 显示内容的长度
              var SHOW_WORD_LENGTH = 200;
              // 命中关键词前的字符显示长度
              var SHOW_WORD_FRONT_LENGTH = 20;
              var SHOW_WORD_END_LENGTH = SHOW_WORD_LENGTH - SHOW_WORD_FRONT_LENGTH;

              // 截取匹配的第一个字符，前后共 200 个字符来显示
              if (contentHitSlice.length > 0) {
                var firstIndex = contentHitSlice[0].index;
                var start = firstIndex > SHOW_WORD_FRONT_LENGTH ? firstIndex - SHOW_WORD_FRONT_LENGTH : 0;
                var end = firstIndex + SHOW_WORD_END_LENGTH;
                postContent = highlightKeyword(content, contentHitSlice, start, end);
              } else { // 未匹配到内容，直接截取前 200 个字符来显示
                postContent = content.slice(0, SHOW_WORD_LENGTH);
              }
              postData.title = postTitle;
              postData.content = postContent;
              postData.url = postURL;
              postData.weight = postWeight;
              matchPosts.push(postData);
            }
          });
        }

        var resultInnerHtml = '';
        if (matchPosts.length) {
          // 按权重递增的顺序排序，使权重大的优先显示
          matchPosts.sort(function (left, right) {
            return right.weight - left.weight;
          });
          resultInnerHtml += '<ul>';
          matchPosts.forEach(function (post) {
            resultInnerHtml += '<li><a class="search-results-title" href="' + post.url + '">';
            resultInnerHtml += post.title;
            resultInnerHtml += '</a><div class="search-results-content">';
            resultInnerHtml += post.content;
            resultInnerHtml += '</div></li>';
          });
          resultInnerHtml += '</ul>';
        } else {
          resultInnerHtml += '<div class="search-results-none"><i class="far fa-meh"></i></div>';
        }
        $result.html(resultInnerHtml);
      };
      $input.on('input', searchPost);
      $input.on('keyup', function (e) {
        if (e.keyCode === Stun.utils.codeToKeyCode('Enter')) {
          searchPost();
        }
      });
    }
  });
}

function closeSearch () {
  $('body').css({ overflow: 'auto' });
  $('.search-popup').css({ display: 'none' });
  $('.search-mask').css({ display: 'none' });
}

window.addEventListener('DOMContentLoaded', function () {
  Stun.utils.pjaxReloadLocalSearch = function () {
    $('.header-nav-search').on('click', function (e) {
      e.stopPropagation();
      $('body').css('overflow', 'hidden');
      $('.search-popup')
        .velocity('stop')
        .velocity('transition.expandIn', {
          duration: 300,
          complete: function () {
            $('.search-popup input').focus();
          }
        });
      $('.search-mask')
        .velocity('stop')
        .velocity('transition.fadeIn', {
          duration: 300
        });

      initSearch();
    });
    $('.search-mask, .search-close').on('click', function () {
      closeSearch();
    });
    $(document).on('keydown', function (e) {
      // Escape <=> 27
      if (e.keyCode === Stun.utils.codeToKeyCode('Escape')) {
        closeSearch();
      }
    });
  };

  Stun.utils.pjaxReloadLocalSearch();
}, false);</script><script src="https://cdn.jsdelivr.net/npm/gitalk@latest/dist/gitalk.min.js"></script><script src="https://cdn.jsdelivr.net/npm/js-md5@latest/src/md5.min.js"></script><script>function loadGitalk () {
  if (!document.getElementById('gitalk-container')) {
    return;
  }

  var gitalk = new Gitalk({
    id: md5(window.location.pathname.slice(1)),
    clientID: '6ca09daabba4f7147cee',
    clientSecret: 'ded593f333a1a88bfb1a5e39e8227c3afc71e08f',
    repo: 'sunyubk.github.io',
    owner: 'sunyubk',
    admin: ['sunyubk'],
    distractionFreeMode: 'true',
    language: 'zh-CN'
  });
  gitalk.render('gitalk-container');
}

if (false) {
  loadGitalk();
} else {
  window.addEventListener('DOMContentLoaded', loadGitalk, false);
}</script><script src="/js/utils.js?v=2.0.0-rc.0"></script><script src="/js/stun-boot.js?v=2.0.0-rc.0"></script><script src="/js/scroll.js?v=2.0.0-rc.0"></script><script src="/js/header.js?v=2.0.0-rc.0"></script><script src="/js/sidebar.js?v=2.0.0-rc.0"></script><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"jsonPath":"/live2dw/assets/shizuku.model.json"},"display":{"position":"left","width":250,"height":500},"mobile":{"show":false},"log":false});</script></body></html>